﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreUtils.Common
{
    public class Number
    {
        /// <summary>
        /// Generate random number from min to max
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns>int</returns>
        /// <remarks>xula@vnext.vn</remarks>
        public static int genRandom(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }

        /// <summary>
        /// Generate random number from 0 to max
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns>int</returns>
        /// <remarks>xula@vnext.vn</remarks>
        public static int genRandom(int max)
        {
            return Number.genRandom(0, max);
        }

        /// <summary>
        /// Check if a string is a number limited by upper and lower bounds
        /// </summary>
        /// <param name="s">string</param>
        /// <param name="min">lower bound</param>
        /// <param name="max">upper bound</param>
        /// <returns>true or false</returns>
        /// <remarks>xula@vnext.vn</remarks>
        public static bool isNumberBounded(string s, int min, int max)
        {
            int value;
            if (!int.TryParse(s, out value) || value < min || value > max)
                return false;
            return true;
        }

        /// <summary>
        /// Check a number with lower bound
        /// </summary>
        /// <remarks>xula@vnext.vn</remarks>
        public static bool isNumberBoundedBelow(string s, int min)
        {
            return isNumberBounded(s, min, int.MaxValue);
        }
    }
}
